# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=stlink
pkgver=1.7.0
pkgrel=1
pkgdesc="STM32 discovery line linux programmer"
url="https://github.com/texane/stlink"
arch="all"
license="MIT"
makedepends="cmake libusb-dev"
options="!check" # upstream doesn't have automated tests
subpackages="$pkgname-doc $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/texane/stlink/archive/v$pkgver.tar.gz
	Fixed-get-flash-base-address-for-STM32L152RE.patch
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DSTLINK_LIBRARY_PATH=/usr/lib \
		-DCMAKE_C_FLAGS="$CFLAGS -Wno-error=cpp" \
		-DSTLINK_UDEV_RULES_DIR=/usr/lib/udev/rules.d \
		$CMAKE_CROSSOPTS .
	make -C build
}

package() {
	make -C build DESTDIR="$pkgdir" install

	mkdir -p "$pkgdir"/usr/share/doc/$pkgname
	install -m644 README.md CHANGELOG.md doc/tutorial.md \
		"$pkgdir"/usr/share/doc/$pkgname/
}

sha512sums="
58b73c7a73809f36ab8ef53370bcbdba7456433c8559f350349febd282188541184b5c171eb2ca1ad38ec4b3ae32d3a89895a208bcacc264ec0aed5f61e6bcd0  stlink-1.7.0.tar.gz
7c3f61de5952bf0d4e43bdf3fce480f1b9655c2df29f94f71c9ccd709e8b24abb0db0a96525fc8c34bf7eada9ec165530c299f4cea33abc16b0431d301c08077  Fixed-get-flash-base-address-for-STM32L152RE.patch
"
